home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / BBEdit / MacBob 1.0ß2 / Source / Exceptions.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  3.1 KB  |  93 lines  |  [TEXT/KAHL]

  1. /***
  2.   *
  3.   *    Exceptions.h
  4.   *    Copyright © 1992-1995 by Christopher E. Hyde.  All rights reserved.
  5.   *
  6.   *    Version:    1.06                11/95
  7.   *
  8.   ***/
  9.  
  10. #pragma once
  11.  
  12. #ifndef __TYPES__
  13. #include <Types.h>
  14. #endif
  15.  
  16.  
  17. struct FailInfo {
  18.     long        jumpBuf[12];        // old 68K:  D2-D7,PC,A2-A4,A6,SP
  19.     FailInfo*    nextInfo;            // Next in stack.
  20. };
  21.  
  22. #ifndef qNoExceptionGlobals
  23. extern FailInfo*    gTopHandler;    // Pointer to the top level (most recent) handler
  24. extern short        gFailE;
  25. extern long        gFailM;
  26. #endif
  27.  
  28. #define    TRY            { FailInfo __fi; if (DoTry(&__fi)) {
  29. #define    CATCH        Success(); } else {
  30. #define    RETRY        Retry(&__fi);
  31. #define    RESIGNAL        Failure();
  32. #define    ENDTRY        } }
  33.  
  34.  
  35. extern "C" int DoTry (FailInfo* fi);
  36.     // Call this to set up an exception handler.  This pushes your handler onto a stack of exception handlers.
  37.  
  38. pascal long BuildMessage (short lowWord, short highWord) = 0x2E9F;    // MOVE.L (A7)+,(A7)
  39.     // Takes the 2 shorts and combines them into a long failure message.
  40.     // Note that the low-order word is the first parameter.
  41.  
  42. pascal void Fail (short error);
  43. #pragma noreturn(Fail)
  44.  
  45. void Failure (void);
  46. #pragma noreturn(Failure)
  47. void Failure (short error, long message);
  48. #pragma noreturn(Failure)
  49.     // Call this to signal a failure.  Control will branch to the most recent
  50.     // exception handler, which will be popped off the handler stack.
  51.  
  52. inline void Throw (short id) { Fail(id); }
  53. #pragma noreturn(Throw)
  54. inline void Throw (short id, long message) { Failure(id, message); }
  55. #pragma noreturn(Throw)
  56.  
  57. pascal void FailMemError (void);
  58.     // if (MemError() != noErr) Fail(MemError());  (See the discussion of MemError in Inside Macintosh.)
  59.  
  60. pascal void FailResError (void);
  61.     // if (ResError() != noErr) Fail(ResError());
  62.  
  63. pascal void FailNewMessage (short error, long oldMessage, long newMessage);
  64.     // This does:    if (oldMessage == 0) oldMessage = newMessage;
  65.     //            Failure(err, oldMessage);
  66.  
  67. pascal void FailNil (void* p);
  68.     // Call this with a pointer/handle; this signals Fail(memFullErr) if p is nil.
  69.  
  70. pascal void FailNilResource (void* r);
  71.     // Call this with a resource handle; this signals Failure if the handle is nil. The error is
  72.     // either that returned by ResError, or resNotFound if ResError returns no error.
  73.  
  74. pascal void FailOSErr (OSErr error);
  75.     // Call this with an OSError; signals Fail(error) if error ≠ noErr.
  76.  
  77. pascal Boolean HandlerExists (FailInfo* testFi);
  78.     // This test returns true if the failure handler exists in the stack from gTopHandler to the outermost handler.
  79.  
  80. void Success (void);
  81. void Success (FailInfo* fi);
  82.     // Call this when you want to pop your exception handler.  We assume that the programmer passes in the
  83.     // most recent FailInfo record; ie. the one that is the top of the stack. If debugging is on, we check to be sure.
  84.  
  85. pascal void Retry (FailInfo* fi);
  86.  
  87. pascal void ProgramBreak (ConstStr255Param grievance);
  88.     // ProgramBreak: Your app can call this when it comes to a situation that you do not expect and cannot
  89.     // handle gracefully.  It beeps and calls DebugStr.
  90.  
  91. pascal void ProgramReport (ConstStr255Param grievance, Boolean brk);
  92.     // Same as ProgramBreak but it only stops in debugger if brk is true.
  93.